package online.longzipeng.cinemasys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import online.longzipeng.cinemasys.entity.Vip;
import online.longzipeng.cinemasys.mapper.VipMapper;
import online.longzipeng.cinemasys.service.VipService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import online.longzipeng.cinemasys.vo.vip.VipQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzp
 * @since 2021-04-26
 */
@Service
public class VipServiceImpl extends ServiceImpl<VipMapper, Vip> implements VipService {

    @Autowired
    VipMapper vipMapper;

    @Override
    public void add(Vip vip) {
        save(vip);
    }

    @Override
    public void updateVip(Vip vip) {
        updateById(vip);
    }

    @Override
    public IPage<Vip> getListPage(VipQueryVO queryVO) {
        Page<Vip> vipPage = new Page<Vip>(queryVO.getPage(),queryVO.getSize());
        QueryWrapper<Vip> qw = new QueryWrapper<>();
        qw.like(!StringUtils.isEmpty(queryVO.getName()),"name",queryVO.getName());
        // 判断排序
        if ("desc".equals(queryVO.getSort())) {
            qw.orderByDesc("id");
        }else {
            qw.orderByAsc("id");
        }
        return page(vipPage,qw);
    }
}
